package com.luocj.muke.common.dialog.dialog;

import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;

public class CustomDialog extends BaseDialog {
    private ViewConvertListener viewConvertListener;

    public static CustomDialog init(){
        return new CustomDialog();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (null != savedInstanceState){
            viewConvertListener = savedInstanceState.getParcelable("listener");
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putParcelable("listener",viewConvertListener);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        viewConvertListener = null;
    }

    @Override
    protected void convertView(ViewHolder holder, BaseDialog baseDialog) {
        if (null!=viewConvertListener){
            viewConvertListener.convertView(holder,baseDialog);
        }
    }

    public CustomDialog setLayoutid(@LayoutRes int layoutId){
        this.layoutId = layoutId;
        return this;
    }

    public CustomDialog setConvertListener(ViewConvertListener listener){
        this.viewConvertListener = listener;
        return this;
    }

    @Override
    public int initLayouId() {
        return layoutId;
    }
}
